home *** CD-ROM | disk | FTP | other *** search
- /***************************************************************************/
- /* */
- /* FILE_check_lpt_available . . . . Check if DOS printer is available, */
- /* starting with level 2 file pointer */
- /* handle_check_lpt_available . . . Check if DOS printer is available, */
- /* starting with level 1 file handle. */
- /* */
- /* not_available = FILE_check_lpt_available(fp); */
- /* not_available = handle_check_lpt_available(handle); */
- /* */
- /* int not_available; 1 if printer is not available, */
- /* 0 if printer is available */
- /* FILE *fp; File pointer */
- /* int handle; File handle */
- /* */
- /* These functions force an exit with error level 100 if they can not */
- /* preempt or restore the DOS critical error handler. */
- /* These functions require DOS 2.0 or later to run. They rely on the */
- /* calling program to check whether it is installed. */
- /* */
- /* I designed these functions for use with Lattice C, Version 3. Some */
- /* of their features which may not be portable are: */
- /* fileno() is an UNIX function which returns the file handle for a */
- /* file pointer. */
- /* Lattice classes onerror(action) as a MSDOS function. onerror(1) */
- /* preeempts the MSDOS critical error handler. onerror(0) restores the */
- /* MSDOS critical error handler. */
- /* union REGS is a Lattice union which lets the registers become */
- /* arguments to functions which invoke 8086 interrupts. intdos is one */
- /* such Lattice function which invokes interrupt 21H. */
- /* */
- /* Full identifiers in these functions conform to the proposed ANSI */
- /* standard of at most 31 significant characters, and they are different */
- /* within the first 8 characters. Lattice C includes a -n compiler */
- /* switch which changes the number of significant characters in */
- /* identifiers from 8 to 39. While these functions work without it, I */
- /* designed them to use it. */
- /* */
- /* Lew Paper */
- /* 5/16/87 */
- /***************************************************************************/
-
- #include <stdio.h>
- #include <dos.h>
- extern char _OSCEF; /* Lattice system variable. Flag for */
- /* critical error. A critical error */
- /* sets it to 3, and these functions */
- /* then resets it to 1. If there is */
- /* no critical error, it is 0. */
- extern short _OSERR; /* Lattice system variable. Operating */
- /* system error code. 83 for a */
- /* critical error. */
-
- int FILE_check_lpt_available(fp)
- FILE *fp;
-
- {
- return handle_check_lpt_available(fileno(fp));
- }
-
- int handle_check_lpt_available(handle)
- int handle;
-
- {
- union REGS reg;
- int not_available;
-
- if (onerror(1)) /* Preempt MSDOS critical error */
- /* handler. */
- {
- fputs("onerror(1) failed in handle_check_lpt_available\n\n", stderr);
- exit(100);
- }
-
- reg.x.ax = 0x4407; /* Check device output status */
- reg.x.bx = handle;
- (void) intdos(®, ®);
- if (_OSCEF == 3) /* Critical error */
- {
- _OSCEF = 1; /* Lattice requires at least one */
- /* settings, and maybe both. */
- _OSERR = 83;
- not_available = 1;
- }
- else
- not_available = !reg.h.al; /* AL = 0xff if the printer is */
- /* available or 0 if it is not */
-
- if (onerror(0)) /* Restore MSDOS critical error */
- {
- fputs("onerror(0) failed in handle_check_lpt_available\n\n", stderr);
- exit(100);
- }
-
- return not_available;
- }